package net.cnki.sunny.exception;

import cn.hutool.core.exceptions.ValidateException;
import net.cnki.sunny.common.ResultVO;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResultVO handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
        ResultVO resultVO = new ResultVO();
        return resultVO.error(e.getBindingResult().getFieldError().getDefaultMessage());
    }
}
